package com.线程;

public class 锁测试 {

    final static Object ob = new Object();
    public static void main(String[] args) {


        new Thread(()->{
            synchronized (ob){
                log("获取obj锁");
                sleep(2000);
                try {
                    log("释放进入等待");
                    ob.wait();
                    log("dengdai");
                    sleep(4000);
                    log("我将要结束");
                    sleep(1000);
                    log("我结束了");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }).start();

        new Thread(()->{
            log( "我将获取锁");
            synchronized (ob){
                log("获取锁");

                // ob.notify();
            }
        }).start();

    }


    private  static void log(String txt){
        System.out.println(Thread.currentThread().getName() + ":" + txt);
    }

    private  static void sleep(long l)  {
        try {
            Thread.sleep(l);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
